package cn.itcast.bos.mq;

import javax.jms.JMSException;
import javax.jms.MapMessage;
import javax.jms.Message;
import javax.jms.MessageListener;

import org.springframework.stereotype.Service;

import com.aliyuncs.dysmsapi.model.v20170525.SendSmsResponse;
import com.aliyuncs.exceptions.ClientException;

import cn.itcast.bos.utils.AliSmsUtils;

@Service
public class SmsConsumer implements MessageListener {

	@Override
	public void onMessage(Message message) {
		MapMessage mapMessage = (MapMessage) message;

		SendSmsResponse response = null;
		try {
			response = AliSmsUtils.sendSms(mapMessage.getString("telephone"), mapMessage.getString("username"),
					mapMessage.getString("randomCode"));
		} catch (Exception e) {
			e.printStackTrace();
			System.out.println();
		}

		if (response.getCode() != null && response.getCode().equals("OK")) {
			System.out.println("发送短信成功!");
		}

	}

}
